import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
		userinfo:{
			id: 0,
			phone: "",       //手机号
			nickname: "",               //昵称
			avatar: "",                 //头像
			sex: "",                    //性别
			birth: "",                  //生日
			is_vip: false,              //是否是会员
			is_certification: false,    //是否认证【个人中心推广信息时需使用判断，非认证需要先认证】
			income: 0,                  //总收益
			can_withdraw_income: 0,     //可提现收益
			freeze_income: 0,			//冻结中收益
			bound_phone: true,          //是否绑定手机
			bound_wechat: false         ,//是否绑定微信
			bound_weapp: false         //是否绑定微信小程序
		},
		searchlist:[] , //搜索历史列表
		music:uni.createInnerAudioContext()
    },
    mutations: {
		//更新搜索历史
		setSearch(state,searchData){
			state.searchlist = searchData;
		},
		//退出登录
        logout(state) {
			state.userinfo = {
				id: 0,
				phone: "",
				nickname: "",
				avatar: "",
				sex: "",
				birth: "",
				is_vip: false,
				is_certification: false,
				income: 0,
				can_withdraw_income: 0,
				bound_phone: true,
				bound_wechat: false
			}
        },
		//设置用户信息
		setUsers(state, userData){
			console.log(userData.userinfo)
			state.userinfo = userData.userinfo ? userData.userinfo : state.userinfo;
		},
		setPhone(state, userData){
			state.userinfo.phone = userData.phone;
		},
		playMusic(state,src){
			
			state.music.autoplay = true; //自动播放
			state.music.loop = false; //循环播放
			state.music.src = src; //背景音乐地址
			state.music.volume = .5; //音量
		},
		playMusicStop(state){
			state.music.pause()
		}
    }
})

export default store
